# -*- coding: utf-8 -*-
from venv1.Page.productInfoPage import productInfoPage
from selenium.common.exceptions import NoSuchElementException
import time
class productInfo():
    def __init__(self, driver):
        self.driver = driver
        self.productinfopage = productInfoPage(self.driver)

    def productinfo(self, list_data):
        time.sleep(4)
        self.productinfopage.signDate().send_keys(list_data[56])
        self.productinfopage.collectionDate().send_keys(list_data[57])
        time.sleep(2)
        self.productinfopage.chargePerson().send_keys(list_data[59])
        time.sleep(2)
        self.productinfopage.plan().click()
        time.sleep(3)
        self.productinfopage.plan().click()
        time.sleep(2)
        self.productinfopage.addinsuredPerson().click()
        time.sleep(1)
        if list_data[29] == "本人":
            self.productinfopage.addinsuredPersonConfirm(list_data[0]).click()
        else:
            self.productinfopage.addinsuredPersonConfirm(list_data[60]).click()
        time.sleep(1)
        self.productinfopage.package().click()
        time.sleep(1)
        self.productinfopage.packageConfirm(list_data[61]).click()
        time.sleep(1)
        self.productinfopage.insuranceTypePlan().click()
        time.sleep(1)
        self.productinfopage.insuranceTypePlanConfirm(list_data[61][3:7]).click()
        self.productinfopage.control().click()
        time.sleep(2)
        if list_data[65] == '无':
            self.productinfopage.confirm().click()
        else:
            self.addition = list_data[65].split("|")
            num = 1
            for additionlist in self.addition:
                addnum = additionlist.split(",")
                self.productinfopage.addinsuredPerson().click()
                time.sleep(1)
                self.productinfopage.addinsuredPersonConfirm(list_data[60]).click()
                if num >= 2:
                    self.productinfopage.insuranceTypePlan01().click()
                else:
                    self.productinfopage.insuranceTypePlan().click()
                time.sleep(1)
                self.productinfopage.insuranceTypePlanConfirm(addnum[0]).click()
                time.sleep(1)
                self.productinfopage.control().click()
                time.sleep(2)
                num = num + 1
            time.sleep(3)
            self.productinfopage.confirm().click()
        time.sleep(1)
        self.productinfopage.insuredAmount().send_keys(list_data[62])
        self.productinfopage.payment().click()
        time.sleep(1)
        self.productinfopage.paymentConfirm(list_data[63]).click()
        self.productinfopage.protect().click()
        time.sleep(1)
        self.productinfopage.protectConfirm(list_data[64]).click()
        if list_data[65] == '无':
            pass
        else:
            self.addition01 = list_data[65].split("|")
            num = 2
            for additionlist01 in self.addition01:
                addnum01 = additionlist01.split(",")
                self.productinfopage.additional(num).send_keys(addnum01[1])
                self.productinfopage.addpayment(num).click()
                time.sleep(1)
                self.productinfopage.addpaymentConfirm(addnum01[2]).click()

                self.productinfopage.addprotect(num).click()
                time.sleep(1)
                self.productinfopage.addprotectConfirm(addnum01[3]).click()
                num = num + 1
        self.productinfopage.paymentType(list_data[66]).click()
        self.productinfopage.expayment(list_data[67]).click()
        try:
            self.productinfopage.annuity()
        except NoSuchElementException:
            pass
        else:
            self.productinfopage.annuityConfirm(list_data[68]).click()
        self.productinfopage.Premium().click()
        time.sleep(1)
        if list_data[71] == '法定':
            time.sleep(1)
            self.productinfopage.Beneficiary(list_data[71]).click()
        else:
            time.sleep(1)
            self.productinfopage.addBeneficiaryAppoint().click()
            time.sleep(1)
            self.productinfopage.beneficiaryName().send_keys(list_data[72])
            self.productinfopage.beneficiarySex().click()
            time.sleep(1)
            self.productinfopage.beneficiarySexConfirm(list_data[73]).click()
            self.productinfopage.beneficiaryIDType().click()
            time.sleep(1)
            self.productinfopage.beneficiaryIDTypeCon(list_data[74]).click()
            self.productinfopage.beneficiaryIDnum().send_keys(list_data[75])
            self.productinfopage.beneficiaryBirth().send_keys(list_data[76])
            self.productinfopage.beneficiaryRelation().click()
            time.sleep(1)
            self.productinfopage.beneficiaryRelationCon(list_data[77]).click()
            self.productinfopage.beneficiaryOrder().click()
            time.sleep(1)
            self.productinfopage.beneficiaryOrdercon(list_data[78]).click()
            self.productinfopage.beneficiaryRatio().send_keys(list_data[79])
        self.productinfopage.accountInfomation().click()
        time.sleep(1)
        self.productinfopage.accountName().click()
        time.sleep(1)
        self.productinfopage.accountNameCon(list_data[0]).click()
        self.productinfopage.CardType().click()
        time.sleep(1)
        cardtypes = list_data[81].split(",")
        for cardtype in cardtypes:
            self.productinfopage.CardTypeCon(cardtype).click()
        self.productinfopage.CardNum().send_keys(list_data[82])
        self.productinfopage.CardBank().click()
        time.sleep(1)
        self.productinfopage.CardBankCon(list_data[83]).click()
        time.sleep(1)
        self.productinfopage.next().click()












